package com.multicampus.minishop.view.product;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.multicampus.minishop.common.SearchVO;
import com.multicampus.minishop.framework.Action;
import com.multicampus.minishop.services.product.ProductService;
import com.multicampus.minishop.services.product.impl.ProductServiceImpl;

public class ProductListAction extends Action {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("euc-kr");

		SearchVO searchVO = new SearchVO();
		int page = 1;
		if (request.getParameter("page") != null)
			page = Integer.parseInt(request.getParameter("page"));

		searchVO.setPage(page);
		searchVO.setSearchCondition(request.getParameter("searchCondition"));
		searchVO.setSearchKeyword(request.getParameter("searchKeyword"));
		
		System.out.println(request.getParameter("searchCondition") + ".............." + request.getParameter("searchKeyword") );

		String pageUnit = getServletContext().getInitParameter("pageUnit");
		searchVO.setPageUnit(Integer.parseInt(pageUnit));

		ProductService service = new ProductServiceImpl();
		HashMap map = service.getProductList(searchVO);
		request.setAttribute("map", map);
		request.setAttribute("searchVO", searchVO);
		return "forward:/product/ProductList.jsp";
	}

}
